// 应用核心类型定义

import type { TabInfo } from './chrome';

// 页面分析相关类型
export interface AnalysisOptions {
  includeHeadings?: boolean;
  includeLinks?: boolean;
  includeImages?: boolean;
  includeMetadata?: boolean;
  maxLinks?: number;
  maxHeadings?: number;
}

export interface HeadingInfo {
  level: number; // h1=1, h2=2, etc.
  text: string;
  id?: string;
}

export interface LinkInfo {
  text: string;
  href: string;
  title?: string;
  external?: boolean;
}

export interface ImageInfo {
  src: string;
  alt?: string;
  title?: string;
  width?: number;
  height?: number;
}

export interface PageAnalysisResult {
  url: string;
  title: string;
  wordCount: number;
  readingTime: number; // 分钟
  headings: HeadingInfo[];
  links: LinkInfo[];
  images?: ImageInfo[];
  metadata?: Record<string, string>;
  timestamp: number;
}

// 扩展设置类型
export interface ExtensionSettings {
  // 通用设置
  theme: 'light' | 'dark' | 'auto';
  language: 'zh' | 'en';

  // 功能开关
  enablePageAnalysis: boolean;
  enableTextHighlight: boolean;
  enableFloatingButton: boolean;
  enableContextMenu: boolean;
  enableAutoAnalysis: boolean;

  // 分析设置
  analysisOptions: AnalysisOptions;

  // 界面设置
  sidebarWidth: number;
  showToolbar: boolean;
  compactMode: boolean;

  // 数据设置
  maxHistoryItems: number;
  clearDataOnClose: boolean;
  syncSettings: boolean;
}

// 用户偏好设置
export interface UserPreferences {
  // 快捷键
  shortcuts: Record<string, string>;

  // 自定义CSS
  customStyles?: string;

  // 排除的网站
  excludedSites: string[];

  // 收藏的分析结果
  favoriteAnalysis: string[];

  // 最近访问的页面
  recentPages: string[];
}

// 活动记录
export interface ActivityItem {
  id: string;
  action: string;
  details: string;
  timestamp: string;
  url?: string;
  tabId?: number;
  data?: Record<string, any>;
}

// 应用状态
export interface AppState {
  // 当前标签信息
  currentTab: TabInfo | null;

  // 当前页面分析结果
  currentAnalysis: PageAnalysisResult | null;

  // 是否正在分析
  isAnalyzing: boolean;

  // 标签页数量
  tabsCount: number;

  // 扩展状态
  extensionStatus: 'active' | 'inactive' | 'error';

  // 最近活动
  recentActivity: ActivityItem[];

  // 错误信息
  error: string | null;

  // 加载状态
  loading: boolean;
}

// 路由类型
export interface RouteInfo {
  name: string;
  path: string;
  title: string;
  icon?: string;
  hidden?: boolean;
}

// 通知类型
export interface NotificationInfo {
  id: string;
  type: 'info' | 'success' | 'warning' | 'error';
  title: string;
  message: string;
  duration?: number;
  actions?: Array<{
    label: string;
    action: () => void;
  }>;
}

// 表单验证
export interface ValidationRule {
  required?: boolean;
  minLength?: number;
  maxLength?: number;
  pattern?: RegExp;
  validator?: (value: any) => boolean | string;
}

export interface FormField {
  name: string;
  label: string;
  type: 'text' | 'number' | 'boolean' | 'select' | 'textarea';
  value: any;
  rules?: ValidationRule[];
  options?: Array<{ label: string; value: any }>;
  placeholder?: string;
  disabled?: boolean;
}